# -*- coding: utf-8 -*-


from django.core.cache import cache
from django.http import HttpRequest, HttpResponse, JsonResponse
from django.utils.deprecation import MiddlewareMixin
import logging

logger = logging.getLogger(__name__)


def def_middleware(get_response):
    def middleware(request):
        logger.info('def_middleware request')
        response = get_response(request)
        logger.info('def_middleware response')
        return response

    return middleware


class MiddlewareClass:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        logger.info('MiddlewareClass request')
        response = self.get_response(request)
        logger.info('MiddlewareClass request')
        return response


class MiddlewareExtends(MiddlewareMixin):

    def process_request(self, request):
        logger.info('before request')
        pass

    def process_response(self, request, response):
        logger.info('after response')

        return response

    def process_exception(self, request, exception):
        logger.info('after exception')

        return JsonResponse({'exception': ''}, status=500)

    # def process_view(self, request, view_func, view_args, view_kwargs):
    #     pass
    #
    # def process_render_template(self, request, response):
    #     pass

    pass
